package com.aidex.web.controller.biz;

import com.aidex.biz.domain.SongsInfo;
import com.aidex.biz.service.SongsInfoService;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.SecurityUtils;
import com.aidex.common.utils.poi.ExcelUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 演唱会信息Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2023-07-07
 */
@RestController
@RequestMapping("/biz/bizSongsInfo")
public class SongsInfoController extends BaseController
{
    @Autowired
    private SongsInfoService songsInfoService;

    /**
     * 查询演唱会信息列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSongsInfo:list')")
    @GetMapping("/list")
    public R<PageInfo> list(SongsInfo songsInfo, HttpServletRequest request, HttpServletResponse response)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            songsInfo.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
         }
        songsInfo.setPage(new PageDomain(request, response));
        return R.data(songsInfoService.findPage(songsInfo));
    }

    /**
     * 获取演唱会信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSongsInfo:query')")
    @GetMapping(value = "/{id}")
    public R<SongsInfo> detail(@PathVariable("id") String id)
    {
        return R.data(songsInfoService.get(id));
    }

    /**
     * 新增演唱会信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSongsInfo:add')")
    @Log(title = "演唱会信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  SongsInfo songsInfo)
    {
        songsInfo.setBeleft(songsInfo.getTotel());
        return R.status(songsInfoService.save(songsInfo));
    }

    /**
     * 修改演唱会信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSongsInfo:edit')")
    @Log(title = "演唱会信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated SongsInfo songsInfo)
    {
        songsInfo.setBeleft(songsInfo.getTotel());
        return R.status(songsInfoService.save(songsInfo));
    }


    /**
     * 删除演唱会信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSongsInfo:remove')")
    @Log(title = "演唱会信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(songsInfoService.deleteSongsInfoByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSongsInfo:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(songsInfoService.findMaxSort(new SongsInfo()));
    }

    /**
     * 导出演唱会信息列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizSongsInfo:export')")
    @Log(title = "演唱会信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(SongsInfo songsInfo)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    songsInfo.setCompanyId(null);
            }else{
                         songsInfo.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<SongsInfo> list = songsInfoService.findList(songsInfo);
        ExcelUtil<SongsInfo> util = new ExcelUtil<SongsInfo>(SongsInfo.class);
        return util.exportExcel(list, "演唱会信息数据");
    }

}
